package com.lvan.fileupload.bean;

import lombok.Data;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Lvan
 */
@Data
public class ResultMsg {

    private boolean success;
    private Integer code;
    private String message;
    private Map<String, Object> data = new HashMap<String, Object>();

    public ResultMsg() {
    }

    public static ResultMsg success() {
        ResultMsg resultMsg = new ResultMsg();
        resultMsg.setSuccess(true);
        resultMsg.setCode(ResultCode.SUCCESS);
        resultMsg.setMessage("成功");
        return resultMsg;
    }

    public static ResultMsg error() {
        ResultMsg resultMsg = new ResultMsg();
        resultMsg.setSuccess(false);
        resultMsg.setCode(ResultCode.ERROR);
        resultMsg.setMessage("失败");
        return resultMsg;
    }

    public ResultMsg message(String message) {
        this.setMessage(message);
        return this;
    }

    public ResultMsg code(Integer code) {
        this.setCode(code);
        return this;
    }

    public ResultMsg data(String key, Object value) {
        this.data.put(key, value);
        return this;
    }

    public ResultMsg data(Map<String, Object> map) {
        this.setData(map);
        return this;
    }
}
